package collection;

import com.sun.xml.internal.ws.policy.privateutil.PolicyUtils;

import java.util.*;

public class Test3 {
    public static void main(String[] args) {
        Random random =new Random();
//        List<Integer> list = new ArrayList<>();
//        for(int i=0;i<10;i++){
//           int  num = random.nextInt(101);
//           list.add(num);
//        }
//        System.out.println("生成的数字随机数："+list);
//        list.sort(((o1, o2) -> o2-o1));//lambda表达式降序
//        System.out.println("排序后的数字随机数："+list);

        //方法二;按照大小排序
        /*
        List<Integer> list = new ArrayList<>();
        //向list集合中存入10个0-100之间的随机整数
        for (int i = 0; i < 10; i++) {
            list.add((int)(Math.random()*101));
        }
        System.out.println(list);
        Collections.sort(list, new Comparator<Integer>() {
            @Override
            public int compare(Integer o1, Integer o2) {
                return o2-o1;
            }
        });

        System.out.println(list);

         */

        //方法三：按照字符串长度排序
        List<String> list = new ArrayList<>();
        //向list集合中存入10个0-100之间的随机整数
        for (int i = 0; i < 10; i++) {
            String num = String.valueOf(random.nextInt(1000));
        }
        System.out.println(list);
        Collections.sort(list, new Comparator<String>() {
            @Override
            public int compare(String o1, String o2) {
                return o2.length() - o1.length();
            }
            });

        System.out.println(list);






    }
}
